<?php
   if($_POST['submit_gallery']!=true) echo '';
   else {
    $gallery_name=trim(addslashes(htmlspecialchars($_POST['gallery'])));
	$gallery_descr=trim(addslashes(htmlspecialchars($_POST['gallery_descr'])));
	$date_added=time();
	$from_who=$_SESSION['username'];
	
	$sel_u = mysql_query('SELECT teacher_to FROM users WHERE username="'.$_SESSION['username'].'"');
	$row_u = mysql_fetch_assoc($sel_u);
	
	if(empty($gallery_name)||empty($gallery_descr)){
	   echo '<p class="error">Моля, попълнете ВСИЧКИ полета!</p>';
	}
	else{
	if(strlen($gallery_name) < 3 || strlen($gallery_descr) < 5){
	   echo '<p class="error">Дължината на името или описанието е много кратка!</p>';
	}
	else{
	   $ins_g=mysql_query('INSERT INTO gallery(`name`, `descr`, `date_added`, `from_who`, `place`) VALUES("'.$gallery_name.'", "'.$gallery_descr.'", '.$date_added.', "'.$from_who.'", "'.$row_u['teacher_to'].'")');
	   echo '<p class="success">Успешен запис!</p>';
	}
	}
   }
?>